

#ifndef _EPOLL_POLLER_H_
#define _EPOLL_POLLER_H_

#include "Poller.hpp"
#include "Timestamp.hpp"
#include <sys/epoll.h>
#include <vector>

namespace zephyr {

class Channel;

class EpollPoller : public Poller {
public:
    EpollPoller(EventLoop *loop);
    ~EpollPoller();
    Timestamp poll(int timeoutMs, ChannelList *activeChannels) override;
    void updateChannel(Channel *channel) override;
    void removeChannel(Channel *channel) override;

private:
    static const int k_initEventListSize = 16;

    void fillActiveChannels(int numEvents, ChannelList *activeChannels) const;
    void update(int operation, Channel *channel);
    using EventList = std::vector<struct epoll_event>;

    int m_epfd;
    EventList m_events;

};

}

#endif // _EPOLL_POLLER_H_